﻿using System;
using System.IO;

namespace LxCore
{
    public class XMLWriter 
    {
        protected StreamWriter Writer;
        protected string Space;
 
        protected void StartWriter()
        {
            Writer.WriteLine("<?xml version=\"1.0\"?>");
            Space = new string(' ', 0);
        }
        protected void WriteXmlHead(string str)
        {
            Writer.WriteLine(string.Format($"{Space}{str}"));
            Space = new string(' ', Space.Length + 2);
        }
        protected void WriteXmlEnd(string str)
        {
            Space = new string(' ', Space.Length - 2);
            Writer.WriteLine(string.Format($"{Space}{str}"));
        }
        protected void WriteSpaceEnter(int index, int interval)
        {
            if (index % interval == 0)
            {
                if (index == 0)
                {
                    Writer.Write(Space);
                }
                else
                {
                    Writer.WriteLine();
                    Writer.Write(Space);
                }
            }
        }
        protected void EndWriter()
        {
            Writer.Close();
        }
    }
}
